<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片切换</title>
</head>
<body>
    <img src="img/brand_goods_1.jpg" id="goods">
    <br>
    <button id="prev">上一张</button>
    <button id="next">下一张</button>
    <script>
        var minIndex = 1,maxIndex = 4;  
        var current = minIndex;
        var goods = document.getElementById('goods');
        var next = document.getElementById('next');
        var prev = document.getElementById('prev');
        next.onclick = function(){
            if(current == maxIndex){
                current = minIndex;
            }else{
                current++;
            }
            goods.setAttribute('src',`img/brand_goods_${current}.jpg`);
            
        }
        prev.onclick = function(){
            if(current == minIndex){
                current = maxIndex;
            }else{
                current--;
            }
            goods.setAttribute('src',`img/brand_goods_${current}.jpg`);
        }
    </script>
    

</body>
</html>